<template>
	<view>
		<DriverListNavbarSwiper ref="navbarSwiper" :navbarList="navbarList" :curNavbar="curNavbar" :height="'88rpx'"
		 :dateList="dateList" @handleChooseNavbar="handleChooseNavbar" @handleScrolltolower="handleScrolltolower"
		 @handleRefresherrefresh="handleRefresherrefresh">
		</DriverListNavbarSwiper>
		
		<CommonAlert ref='alert' :config="alertConfig" @confirm="handleReSubmit"></CommonAlert>
	</view>
	
</template>

<script>
	import CommonAlert from '@/components/common/common-alert.vue'
	import DriverListNavbarSwiper from '@/components/user/driverList-navbarSwiper.vue'
	export default {
		components: {
			DriverListNavbarSwiper,
			CommonAlert
		},
		data() {
			return {
				navbarList: [],
				curIndex: 0,
				curNavbar: {name: '驾驶员1',alias: 'driver1'},
				orderNo: '',
				dirverList: [],
				alertConfig: {
					cancleText: '修改其他人',
					confirmText: '确定',
					content: '是否确定重新提交？'
				}
			};
		},
		onLoad(opt) {
			this.orderNo = opt && opt.orderNo
			this.getDriverList()
			uni.$on('confirmSubmit', () => { // 取消订单成功
				this.$refs.alert.show()
			})
		},
		onUnload() {
			uni.$off('confirmSubmit')
		},
		computed: {
			dateList() {
				let arr = []
				this.dirverList.forEach(item => {
					arr.push([item])
				})
				return arr
			},
		},
		methods: {
			handleReSubmit() { // 确定重新提交订单
				let arr = []
				this.dirverList.forEach(item => {
					arr.push(item.id)
				})
				const rentDriverIds = arr.join()
				this.$http.post(this.$api.resubmit, {orderNo: this.orderNo, rentDriverIds}).then(res => {
					if (res.code === 200) {
						uni.navigateBack({delta: -2});
					}
				})
			},
			handleChooseNavbar(item, i) {
				this.curNavbar = item
				this.curIndex = i
			},
			getDriverList() {
				this.$http.get(this.$api.getSwiperDriverList, {
					orderNo: this.orderNo
				}).then(res => {
					if (res.code === 200) {
						this.dirverList = res.data
						let arr = []
						res.data.forEach((item, index) => {
							arr.push({
								name: '驾驶员' + (index + 1),
								alias: 'driver' + (index + 1)
							})
						})
						this.navbarList = arr
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
